\name{GetPointCountStationID}
\alias{GetPointCountStationID}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{ Get the PRBO station code for a unique site identifier within PRBOd  }
\description{
   This function provides the site code based on the unique numeric id or the station name.
}
\usage{
GetPointCountStationID(SamplingUnitID, station_name, batch, ...)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{SamplingUnitID}{ A vector of SamplingUnitIDs }
  \item{station_name}{A vector of full length point count station names}
  \item{batch}{Boolean variable to denote whether this process should be done in batch mode}
  \item{\dots}{Additional variables that can get passed through to underlying functions}
}
\details{
  This function will query the PRBOdb database and retrieve the
  PRBO station code (generally 4-6 characters) for a given set
  of either unique point identifiers (SamplingUnitIDs) or the
  long descriptive names for stations.
  
  When the \code{batch} argument is set to TRUE, this allows
  the matching process to occur on the users computer after
  one complete download of the species table.  This will be
  much faster if a substantial number of queries need to be
  made.  However, if the number of queries is small then 
  leaving \code{batch} as FALSE will be faster, since the
  database will not need to be downloaded.

}
\value{
  Returns a vector of PointCountStationIDs of the same length as that provided for the search.
}
\author{ Mark Herzog \email{mherzog@prbo.org} }
\seealso{ \code{\link{GetSamplingUnitID}}, \code{\link{GetStationName}} }
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(SamplingUnitID=NULL, station_name=NULL, batch=FALSE,...) {
    if (is.null(SamplingUnitID) & is.null(station_name)) stop("A SamplingUnitID or station_name must be provided")
    if (!is.null(SamplingUnitID)) {
        station.list<-paste("'",SamplingUnitID,"'",sep="",collapse=",")
        query<-paste(   "SELECT PointCountStationID as station, SamplingUnitID as point",
                        "FROM SamplingUnit",
                        "WHERE SamplingUnitTypeCd != 'PointCountStation'"
                )
       if (batch==FALSE) query<-paste(query,"AND SamplingUnitID in (",station.list,")",sep="")
       
    } else {
        station.list<-paste("'",station_name,"'",sep="",collapse=",")
        query<- paste(  "SELECT PointCountStationID as station, SamplingUnitName as point",
                        "FROM SamplingUnit",
                        "WHERE SamplingUnitTypeCd != 'PointCountStation'"
                )    
        if (batch==FALSE) query<-paste(query,"AND SamplingUnitName in (",station.list,")",sep="")
    }
    query.results<-fetch(dbSendQuery(db<-PRBOdbConnect(group="PRBOdb", ...),query),n=-1)
    if (!is.null(SamplingUnitID)) output<-query.results$station[match(SamplingUnitID,query.results$point)]
    if (!is.null(station_name)) output<-query.results$station[match(station_name,query.results$point)]
    dbDisconnect(db)
    return(output)
  }
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
\keyword{ data }
